package com.fish.passport.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fish.common.constant.QueryPage;
import com.fish.common.dao.BaseIbatisDao;
import com.fish.passport.po.PassDevice;

/**
 * 设备编号管理
 * 
 * @author chenlinjun
 * 
 */
@SuppressWarnings("unchecked")
public class PassDeviceDAO extends BaseIbatisDao {
	/**
	 * 添加设备编号信息
	 * 
	 * @param passDevice
	 * @return
	 */
	public void addPaasDevice(PassDevice passDevice) {
		 this.getSqlMapClientTemplate().insert("PASS_DEVICE.insertSelective", passDevice);
	}

	/**
	 * 修改设备编号信息
	 * 
	 * @param passDevice
	 * @return
	 */
	public int updatePaasDevice(PassDevice passDevice) {
		return this.getSqlMapClientTemplate().update("PASS_DEVICE.updateByPrimaryKeySelective", passDevice);
	}

	/**
	 * 通过设备编号和服务商编号查询设备编号信息
	 * 
	 * @param deviceNo
	 * @param providerId
	 * @return
	 */
	public PassDevice getPaasDeviceByDeviceNoAndProviderId(String deviceNo, Integer providerId) {
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("deviceNo", deviceNo);
		data.put("providerId", providerId);
		return (PassDevice) this.getSqlMapClientTemplate().queryForObject(
				"PASS_DEVICE.getPaasDeviceByDeviceNoAndProviderId", data);
	}

	/**
	 * 通过设备编号查询设备编号信息
	 * 
	 * @param deviceId
	 * @return
	 */
	public PassDevice getPaasDeviceByDeviceId(String deviceId) {
		return (PassDevice) this.getSqlMapClientTemplate().queryForObject("PASS_DEVICE.getPaasDeviceByDeviceId",
				deviceId);
	}

	/**
	 * 通过设备编号删除
	 * 
	 * @param deviceId
	 * @return
	 */
	public int delDeviceByDeviceId(String deviceId) {
		return this.getSqlMapClientTemplate().delete("PASS_DEVICE.delDevice",
				deviceId);
	}
	/**
	 * 查询设备编号信息
	 * 
	 * @param param
	 * @return
	 */
	public List<PassDevice> searchPassDevice(Map<String, Object> param) {
		if(!param.containsKey("_startRow")){
			param.put("_startRow", 0L);
		}
		if(!param.containsKey("_endRow")){
			param.put("_endRow", 100000L);
		}
		return this.getSqlMapClientTemplate().queryForList("PASS_DEVICE.searchPassDevice", param);
	}
	
	public int searchPassDeviceCount(Map<String,Object> param){
		return (Integer)this.getSqlMapClientTemplate().queryForObject("PASS_DEVICE.searchPassDeviceCount",param);
	}

	/**
	 * 通过服务商和通关编号查询设备信息
	 * 
	 * @param codeId
	 * @param providerId
	 * @return
	 */
	public List<PassDevice> selectPassDeviceByProviderIdAndCodeId(String codeId, Integer providerId) {
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("codeId", codeId);
		data.put("providerId", providerId);
		return this.getSqlMapClientTemplate().queryForList("PASS_DEVICE.selectPassDeviceByProviderIdAndCodeId", data);
	}
	
	public Long queryPassDeviceCountByObject(PassDevice passDevice){
		return  (Long) this.getSqlMapClientTemplate().queryForObject("PASS_DEVICE.countPassDeviceWithPaging", passDevice);
	}
	
	public  List<PassDevice> queryPassDeviceObject(PassDevice passDevice,QueryPage queryPage){
		passDevice.setBeginItem(queryPage.getBeginItem());
		passDevice.setEndItem(queryPage.getPageSize());
		return (List<PassDevice>) this.getSqlMapClientTemplate().queryForList("PASS_DEVICE.selectPassDeviceWithPaging", passDevice);
	}
}
